import React from 'react'
import 'amis/lib/themes/cxd.css'

import upmsRoleIdSelectUtils from '@/components/upms/upmsRoleIdSelectUtils'
import { SelectControlSchema } from 'amis/lib/renderers/Form/Select'
import smsSendFormUtils from '@/components/sms/smsSendFormUtils'
import RealTimeCodeEditor from '@/components/amis/RealTimeCodeEditor/RealTimeCodeEditor'
import applicationAdminApiConfig from '@/core/application/generated/apiconfig/applicationAdminApiConfig'

const Page = () => {
	const selectSchema = {
		...upmsRoleIdSelectUtils.getSchema({
			name: 'roleId',
		}),
	} as SelectControlSchema
	let schema = {
		type: 'page',
		data: {
			id: 1,
		},
		body: {
			type: 'form',
			initApi: {
				method: applicationAdminApiConfig.appApplication.get.method,
				url: applicationAdminApiConfig.appApplication.get.mockUri,
				data: {
					id: '${id}',
				},
			},
			canAccessSuperData: false,
			data: {
				roleId: 2,
			},
			body: [
				{
					type: 'input-text',
					name: 'title',
					label: 'title',
				},
				{
					name: 'status',
					type: 'input-email',
					label: 'status',
				},
				selectSchema,
			],
		},
	}

	schema = {
		type: 'page',
		body: [
			{
				type: 'button',
				label: '发送短信',
				actionType: 'drawer',
				drawer: {
					title: '发送短信 (Esc退出)',
					showErrorMsg: false,
					position: 'right',
					closeOnEsc: true,
					resizable: true,
					body: smsSendFormUtils.getSchema(),
				},
			},
			{
				label: '新增',
				type: 'button',
				level: 'primary',
				actionType: 'drawer',
				drawer: {
					title: '新增 [账户应用] (Esc退出)',
					position: 'right',
					closeOnEsc: true,
					resizable: true,
					body: {
						type: 'form',
						body: [
							{
								name: 'status',
								type: 'select',
								label: '状态',
								clearable: true,
								options: [
									{
										label: '锁定',
										value: 0,
									},
									{
										label: '正常',
										value: 1,
									},
								],
								required: true,
							},
						],
					},
				},
			},
		],
	} as any
	return <RealTimeCodeEditor code={schema} />
}
export default Page
